
import { stringify } from "qs";
import { dateTimeFormat } from "../../src/utils/time";
import moment from "moment";

export const srPageination_requestFormat = ({ data, params }) => {
    data = { ...(data || {}) };
    if(data.page) {
        data.start = (data.page.pageNo - 1) * data.page.pageSize;
        data.limit = data.page.pageSize;
        data.pageNum = data.page.pageNo;
        data.pageSize = data.page.pageSize;
        data.page = data.page.pageNo;
    }

    return {
        data,
        params,
    };
};
export const samPageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        if(output.page) {
            output.start = output.page.pageNo
            output.page = output.page.pageSize;
        }
        return output;
    };
    if (data) {
            data = handleParams(data);
    }
    if (params) {
            params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const samPageination_requestFormatbak = ({ data, params }) => {
    data = { ...(data || {}) };
    data.startIndex = (data.page.pageNo - 1) * data.page.pageSize + 1;
    data.pageNum = data.page.pageSize;
    delete data.page;
    return {
        data,
        params,
    };
};

export const samPageination_requestFormatbak_two = ({ data, params }) => {
    data = { ...(data || {}) };
    data.startIndex = data.page.pageNo;
    data.pageNum = data.page.pageSize;
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormat = ({ data, params }) => {
   
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = (output.page.pageNo - 1) * output.page.pageSize;
        output.limit = output.page.pageSize;
        output.pageNum = output.page.pageNo;
        output.pageSize = output.page.pageSize;
        output.page = output.page.pageNo;
        return output;
    }

    if(data) {
        data = handleParams(data);
    }
    if(params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const samPageination_requestFormatz = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = (output.page.pageNo - 1) * output.page.pageSize + 1;
        output.page = output.page.pageSize;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const samPageination_requestFormatzc = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.startIndex = (output.page.pageNo - 1) * output.page.pageSize ;
        output.pageNum = output.page.pageSize;
        delete output.page
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormatThree = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = (output.page.pageNo - 1) * output.page.pageSize;
        output.pageNum = output.page.pageSize;
        output.page = undefined;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormat_queryfblist = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = ((output.page.pageNo - 1) * output.page.pageSize) + 1;
        output.pageNum = (((output.page.pageNo - 1) * output.page.pageSize) + 1) + output.page.pageSize;
        output.page = null;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormatbak = ({ data, paramList }) => {
    data = { ...(data || {}) };
    data.startIndex = (data.page.pageNo - 1) * data.page.pageSize;
    data.pageNum = data.page.pageSize;
    if(data.startTime != null){
        data.startTime = dateTimeFormat(data.startTime);
    }
    if(data.endTime != null){
        data.endTime = dateTimeFormat(data.endTime);
    }
    var param = {
        params:JSON.stringify(data)
    }
    return {
        data:param,
        paramList,
    };
};

export const zskPageination_requestFormatbakTwo = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.startIndex = (output.page.pageNo - 1) * output.page.pageSize;
        output.pageNum = output.page.pageSize;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormatbakthree = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.page = (output.page.pageNo - 1) * output.page.pageSize;
        output.size = output.page.pageSize;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const zskPageination_requestFormatTwo = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        if(output.page) {
					output.start = (output.page.pageNo - 1) * output.page.pageSize;
					output.pageNum = output.page.pageSize;
                    output.limit = output.page.pageSize;
					delete output.page
				}
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};
export const outCallPageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        if(output.page) {
            output.start = (output.page.pageNo - 1);
            output.pageNum = output.page.pageSize;
            output.limit = output.page.pageSize;
            delete output.page
        }
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const asradapterPageination_requestFormatTwo = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.size = output.page.pageSize;
        output.page = (output.page.pageNo - 1) * output.page.pageSize + 1;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const monitorPageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {

        let outPut = { ...(input || {}) };
        outPut.pageNum = outPut.page.pageNo;
        outPut.start = outPut.page.pageNo;
        outPut.pageSize = outPut.page.pageSize;
        delete outPut.page;
        return outPut;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};
export const smsPageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {
        let { page,...outPut } = input;
        outPut.pageNum = page.pageNo;
        outPut.pageSize = page.pageSize;
        return outPut;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};
export const monitor_log_Pageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.s = output.page.pageNo - 1;
        output.p = output.page.pageSize;
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const monitor_total_Pageination_requestFormat = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.s = output.page.pageNo - 1;
        output.p = output.page.pageSize;
        output.start = moment(output.start).format("YYYY-MM-DD HH:mm");
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const oneframePageination_requestFormat_qryAgentOperate = ({
    data,
    params,
}) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = (output.page.pageNo - 1) * output.page.pageSize;
        output.pageNum = output.page.pageSize;
        if (output.opTimeStart != null) {
            output.opTimeStart = dateTimeFormat(output.opTimeStart);
        } else {
            output.opTimeStart = "";
        }
        if (output.opTimeEnd != null) {
            output.opTimeEnd = dateTimeFormat(output.opTimeEnd);
        } else {
            output.opTimeEnd = "";
        }
        if (output.opId == null) {
            output.opId = "";
        }
        if (output.opType == null) {
            output.opType = "";
        }
        if (output.targetId == null) {
            output.targetId = "";
        }
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const oneframePageination_requestFormat_qryBusys = ({
    data,
    params,
}) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        output.start = (output.page.pageNo - 1) * output.page.pageSize;
        output.pageNum = output.page.pageSize;
        if (output.starttimeStart != null) {
            output.starttimeStart = dateTimeFormat(output.starttimeStart);
        } else {
            output.starttimeStart = "";
        }
        if (output.starttimeEnd != null) {
            output.starttimeEnd = dateTimeFormat(output.starttimeEnd);
        } else {
            output.starttimeEnd = "";
        }
        if (output.agentid == null) {
            output.agentid = "";
        }
        if (output.siginid == null) {
            output.siginid = "";
        }
        if (output.state == null) {
            output.state =
                "FREE,BUSY,AGENT::SIGNOUT,AGENT::ANSWER_AGENT,AGENT::RING";
        }
        return output;
    };

    if (data) {
        data = handleParams(data);
    }
    if (params) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};
export const pageination_requestFormat_limit = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        if (output?.page) {
            output.start = (output.page.pageNo - 1) * output.page.pageSize;
            output.limit = output.page.pageSize;
            delete output.page;
        }
        return output;
    };

    if (data && Object.keys(data).length) {
        data = handleParams(data);
    }
    if (params && Object.keys(params).length) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};

export const config_Manage_Pageination_requestFormat = ({
    data,
    paramList,
}) => {
    data = { ...(data || {}) };
    const param = JSON.stringify(data);
    return {
        data: data,
        paramList,
    };
};

export const pageination_requestFormat_startIndex = ({ data, params }) => {
    const handleParams = (input) => {
        let output = { ...(input || {}) };
        if (output?.page) {
            output.startIndex = output.page.pageNo;
            output.pageNum = output.page.pageSize;
            delete output.page;
        }
        return output;
    };

    if (data && Object.keys(data).length) {
        data = handleParams(data);
    }
    if (params && Object.keys(params).length) {
        params = handleParams(params);
    }
    return {
        data,
        params,
    };
};
// export const requestFuntion_params = (obj)=> { //table入参多层参数方式

//     let data= obj.params||obj.data
//    if (data && data.page) {
//        data.pageNum = data.page.pageNo;
//        data.pageNo=data.page.pageNo
//        data.pageSize = data.page.pageSize;
//        delete data.page
//    }
//    let params={}
//    Object.keys(data).map(key=>{

//        if(key!='pageNum'&&key!='pageNo'&&key!='pageSize'){
//            params[key]=data[key]
//            delete data[key]
//        }
//    })
//    data.params=params
//    return {
//        data
//    };
// };
export const requestFuntion = (obj)=> { //table入参不带多层参数方式

    let data= obj.params||obj.data
    if (data && data.page) {
        data.pageNum = data.page.pageNo;
        data.pageNo=data.page.pageNo
        data.pageSize = data.page.pageSize;
        delete data.page
    }
    return {
        data
    };
};
export const requestFuntion_outcall = (obj)=> { //外呼不规则分页,
    let data= obj.params||obj.data
    if (data && data.page) {
        data.start = (data.page.pageNo-1)*10;
        data.pageNum=data.page.pageSize
        delete data.page
    }
    return {
        data
    };
};
export const requestFuntion_params = (obj)=> { //培训、外呼不规则分页，内嵌入参bean，params

        let structure=obj.serviceSet?.structure;
        let {page}=structure
        let data=obj.data || obj.params
        if (data && data.page) {
            data[page[0]]=structure.innerparam=='bean'?(data.page.pageNo-1)*10:data.page.pageNo //外呼 启始页从0,10,20 ....,培训1，2，3....
            data[page[1]] = data.page.pageSize;
            delete data.page
        }
        let params={}
        Object.keys(data).map(key=>{
            if(key!='start'&&key!='pageNum'&&key!='pageNo'&&key!='pageSize'){
                params[key]=data[key]
                delete data[key]
            }
        })
        data[structure.innerparam]=params
        return {
            data
        };
};
export const pageination_requestFormat_size = ({ data, params }) => {
	const handleParams = (input) => {
			let output = { ...(input || {}) };
			if(output?.page) {
				output.pageNum = output.page.pageNo;
				output.size = output.page.pageSize;
				delete output.page
			}
			return output;
	};

	if (data && Object.keys(data).length) {
			data = handleParams(data);
	}
	if (params && Object.keys(params).length) {
			params = handleParams(params);
	}
	return {
			data,
			params,
	};
};

export const pageination_requestFormat_pageSize = ({ data, params }) => {
	const handleParams = (input) => {
			let output = { ...(input || {}) };
			if(output?.page) {
				output.pageNo = output.page.pageNo;
				output.pageSize = output.page.pageSize;
				delete output.page
			}
			return output;
	};

	if (data && Object.keys(data).length) {
			data = handleParams(data);
	}
	if (params && Object.keys(params).length) {
			params = handleParams(params);
	}
	return {
			data,
			params,
	};
};

